﻿

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace SLBehaviourSystem
{
    [ActionComponent]
    public class MoveByDirectComponent : MoveComponent
    {
        Vector3 targetPos;
        float angle;
        public IDirectorable director;
        protected override void OnInit()
        {
            base.OnInit();
            director = (IDirectorable)Agent;
        }
        protected override void OnBindNode()
        {
            base.OnBindNode();
            angle = node.BehaviourData.GetFloat("AngleY");

            targetPos = gameObject.transform.position + Quaternion.AngleAxis(angle, director.Up) * director.Forward * Speed;
        }

        protected override void Move(float speed, float distanceOffset)
        {
            bool isEnd = MoveHelper.MoveToPos(gameObject, targetPos, speed, distanceOffset, MoveType.CharacterController);
            if (isEnd)
            {
                enabled = false;
                OnExcuted(BehaviourNodeState.Success);
            }
        }
    }
}

